<template>
    <div>
      <el-switch
      v-model="value1"
      active-text="按月付费"
      inactive-text="按年付费">
    </el-switch>
    <el-switch
      style="display: block"
      v-model="value2"
      active-color="#13ce66"
      inactive-color="#ff4949"
      active-text="按月付费"
      inactive-text="按年付费">
    </el-switch>
        <div v-show="$store.state.sum == 'huang'">
          {{ $store.state.arr }}=={{ getNum }}=={{  }}
          <hr />
          <button @click="ck">加的和是{{ $store.state.sum }}</button>
          <hr />
          <button @click="jia(1)">1</button>
          <button @click="jia(2)">2</button>
        </div>
        <div>
          <h1>当前求和为{{ $store.state.num }}</h1>
          <select v-model="currentId" @change="change($event)">
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
          </select>
          <button @click="dainji(1)">+</button>
          <button @click="dainji(2)">-</button>
          <button @click="dainji(3)">当前求和为奇数在加</button>
          <button @click="dainji(4)">等一等在加</button>
        </div>
        <hr>
        <h1>小窗库</h1>
        {{ $store.state.index.object }}=={{  this.$store.getters['index/changeobject']}}
        <button @click="ck1">点击修改</button>
      </div>
    </template>
    <script>
    import { mapState, mapGetters } from "vuex";
    export default {
      data() {
        return {
          shu: 3,
          currentId: "1",
          value1:true,
          value2:true
        };
      },
    
      created() {
        console.log(this.$store.getters['index/changeobject']);
    
      },
      computed: {
        ...mapState({
          getNum(state) {
            return state.num;
          },
        }),
        ...mapGetters(["firtName"]),
      },
      methods: {
        ck1(){
            console.log(1);
            this.$store.commit('index/changemath')
            // location.reload()
           
            this.$store.dispatch('index/changechinese',1)
            // this.$forceUpdate()
        },
        change(e) {
          this.currentId = e.target.value;
        },
        dainji(e) {
        //   console.log(1);
          if (e == 1) {
            // console.log(this.currentId);
            this.$store.commit("add", ["+", this.currentId]);
          }
    
          if (e == 2) {
            // console.log(this.currentId); 
            this.$store.commit("add", ["-", this.currentId]);
          }
          if (e == 3) {
            if (this.$store.state.num % 2 == 1) {
              this.$store.commit("add", ["+", this.currentId]);
            } else {
              alert("该数为双数");
            }
          }
          if (e == 4) {
            window.setTimeout(()=> {
              this.$store.commit("add", ["+", this.currentId]);
            }, 3000);
          }
        },
        ck() {
          //    this.$store.state.sum+=1
          // 只能传一个参数位，如果要多个，请写成对象或者数组
          this.$store.commit("changeSum", 1);
        },
        jia(e) {
          console.log(this.$store.state.sum % 2);
          if (e == 1) {
            if (this.$store.state.sum % 2 == 1) {
              this.$store.dispatch("cccc", e);
            } else {
              alert("该数为双数");
            }
          } else {
            if (this.$store.state.sum % 2 == 0) {
              this.$store.dispatch("cccc", e);
            } else {
              alert("该数为双数");
            }
          }
        },
      },
    };
    </script>
    <style lang='less' scoped>
    </style>
    